home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
JOHNLOVE
/
C_SOURCE
/
CDEFAULT.C
next >
Wrap
Text File
|
1992-01-25
|
3KB
|
121 lines
/* ---------------------------
** "CDefaultButton.c"
**
** from SPLAsh Resources
** "THINKin' CaP", Winter 1991
** --------------------------- */
#include <CPaneBorder.h>
#include "CDefaultButton.h"
#include "GrayMatters.h"
#define CHAR_Return 13 /* Default button responds to the */
#define CHAR_Enter 3 /* <Return> and <Enter> keys */
void CDefaultButton::IDefaultButton (short CNTLid, CView *anEnclosure,
CBureaucrat *aSupervisor) {
IButton(CNTLid, anEnclosure, aSupervisor);
} /* IDefaultButton */
void CDefaultButton::DoKeyDown (char theChar, Byte keyCode,
EventRecord *macEvent) {
if ( ((theChar == CHAR_Return) || (theChar == CHAR_Enter)) && IsActive() )
SimulateClick();
else inherited::DoKeyDown(theChar, keyCode, macEvent);
} /* DoKeyDown */
void CDefaultButton::SetDefault (Boolean fDefault) {
short roundCorner;
inherited::SetDefault(fDefault);
roundCorner = Max(height/2, 16);
itsBorder->SetRounding(roundCorner, roundCorner);
} /* SetDefault */
void CDefaultButton::Draw (Rect *area) {
LongRect enclAperture;
Rect windRect, defRect;
PenState savePenState;
RGBColor saveForeColor;
short roundCorner;
AuxCtlHandle acHndl;
CCTabHandle ccTable;
Boolean portHasColor;
// inherited method will draw the button itself:
inherited::Draw(area);
// Draw default border within clipping region of Button's Enclosure:
itsEnclosure->GetAperture(&enclAperture);
EnclToFrameR(&enclAperture);
FrameToWindR(&enclAperture, &windRect); /* Controls use Window coords. */
ClipRect(&windRect);
GetPenState(&savePenState);
portHasColor = CurrentPortHasColor();
if (portHasColor) GetForeColor(&saveForeColor);
defRect = (**macControl).contrlRect;
/* Border is 3 pixels wide, outset from the button by 1 pixel.
** The next three statements are accomplished by the DrawBorder
** method. The last is done by the above SetDefault method
** which sets the roundDiameter parm passed to FrameRoundRect
** within the DrawBorder routine:
PenNormal();
PenSize(3, 3);
InsetRect(&defRect, -4, -4);
roundCorner = Max(height/2, 16); */
/* Draw gray border for an inactive button: */
if ( !IsActive() ) SetGrayPen();
else if (portHasColor) {
if (GetAuxCtl(macControl, &acHndl)) {
ccTable = (**acHndl).acCTable;
RGBForeColor(& ((**ccTable).ctTable)[cFrameColor].rgb );
}
}
itsBorder->DrawBorder(&defRect);
/* Avoid ugly flashes if there is also a pending
** update event that will also draw this button: */
itsBorder->CalcBorderRect(&defRect);
ValidRect(&defRect);
if (portHasColor) RGBForeColor(&saveForeColor);
SetPenState(&savePenState);
} /* Draw */
/* end: CDefaultButton.c */